const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatDate = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  return [year,month,day].map(formatNumber).join('-')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

/**
 * 根据租户id判断请求的前缀
 */
const getRequestUrlHeader=id=>{
    let baseApi = ""
    switch (id) {
        case 'shsxhyyebkta001':
          baseApi += 'xinhua'
          break
        case 'xaefynewJCEBta001':
          if (proxy == 'false') {
            baseApi += ''
          } else {
            baseApi += 'xian'
          }
          break
        case 'xaefynewJCEBdept001':
          if (proxy == 'false') {
            baseApi += ''
          } else {
            baseApi += 'xian'
          }
          break
        case 'test':
          baseApi += 'beishengtest'
          break
        case 'beishengxsekta001':
          baseApi += 'beisheng'
          break
        case 'beisheng2xsekta001':
          baseApi += 'beisheng'
          break
        case 'qmxxssfta001':
          baseApi += 'qmx'
          break
        case 'smxzxyyzfta001':
          baseApi += 'smx'
          break
        case 'xsxfybjyzfta001':
          baseApi += 'xs'
          break
          case 'jmszxyyta001':
            baseApi += 'jiangmen'
            break
        default:
          baseApi += ''
      }
      return baseApi
}

module.exports = {
  formatTime: formatTime,
  formatDate:formatDate,
  getRequestUrlHeader:getRequestUrlHeader
}
